package com.czxy.service;

import com.czxy.dao.UserMapper;
import com.czxy.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.sql.Timestamp;
import java.util.Date;

/**
 * @author Liuyunqin 17674029449@163.com
 * @date 2018/12/13 20:49
 */
@Service
@Transactional  //开启事务管理
public class UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * @author 刘韵琴  email:17674029449@163.com
     * @describe 新增用户
     */
    public void saveUser(User user){
        userMapper.insert(user);
    }

    /**
     * @author 刘韵琴  email:17674029449@163.com
     * @describe 根据电话号码查询用户
     */
    public User findMobile(String mobile) {
        User user = userMapper.findByMobile(mobile);
        return user;
    }

    /**
     * @param mobile
     * @param password
     * @describe 根据电话号码和密码查询用户
     */
    public User findMobileAndPassword(String mobile, String password) {
        //1. 拼凑查询条件
        Example example = new Example(User.class);
        example.createCriteria()
                .andEqualTo("mobile",mobile)
                .andEqualTo("password",password);
        //2. 查询
        User user = userMapper.selectOneByExample(example);
        return user;
    }
}
